*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations
CLASS zcl_price_get DEFINITION.
  PUBLIC SECTION.

* Attributes
    DATA:lt_matnr TYPE TABLE FOR CREATE i_producttp_2,
         ls_matnr TYPE i_producttp_2.
    DATA:lv_msg_text TYPE string.

    "库存查询
    METHODS  price_sel
      IMPORTING
                is_data      TYPE ty_json
      RETURNING VALUE(e_msg) TYPE ty_msg.

ENDCLASS.

CLASS zcl_price_get IMPLEMENTATION.

  METHOD price_sel.

    DATA:lt_tab TYPE TABLE OF ty_tab.
    DATA:lt_price TYPE TABLE OF ty_price,
         ls_price TYPE ty_price.

    DATA:lt_pri  TYPE TABLE OF t_price,
         ls_pri  TYPE t_price,
         lt_data TYPE TABLE OF t_data,
         ls_data TYPE t_data.

    SELECT a~product,
           b~productname,
           a~inventoryvaluationprocedure,
           a~standardprice,
           a~movingaverageprice,
           a~currency
      FROM i_productvaluationbasic AS a
      JOIN i_producttext AS b ON a~product = b~product
      WHERE b~language = '1'
      INTO TABLE @lt_tab.

    LOOP AT lt_tab ASSIGNING FIELD-SYMBOL(<fs>).
      ls_price-product = <fs>-product.
      IF <fs>-inventoryvaluationprocedure = 'V'.
        ls_price-price = <fs>-movingaverageprice.
      ELSEIF <fs>-inventoryvaluationprocedure = 'S'.
        ls_price-price = <fs>-standardprice.
      ENDIF.
      ls_price-currency = <fs>-currency.
      APPEND ls_price TO lt_price.
      CLEAR: ls_price.
    ENDLOOP.

    SORT lt_tab BY product.
    DELETE ADJACENT DUPLICATES FROM lt_tab COMPARING product.

    DATA:lv_index TYPE string,
         lv_text  TYPE string.
    LOOP AT lt_tab ASSIGNING <fs>.
      lv_index = 1.
      ls_data-itemcode = <fs>-product.
      ls_data-itemname = <fs>-productname.

      LOOP AT lt_price INTO ls_price WHERE product = <fs>-product.
        CLEAR:lv_text.
        CONCATENATE '价格清单' lv_index INTO lv_text.
        lv_index = lv_index + 1.
        ls_pri-pricedsc = lv_text.
        ls_pri-curreny = ls_price-currency.
        ls_pri-price = ls_price-price.
        APPEND ls_pri TO lt_pri.
        CLEAR:ls_pri,ls_price.
      ENDLOOP.

      ls_data-pricelist = lt_pri.
      APPEND ls_data TO lt_data.
      CLEAR:lv_index,lv_text.
      CONCATENATE '查询物料' ls_data-itemcode  '价格清单成功' INTO lv_text.
      e_msg-state = '0'.
      e_msg-errormsg = lv_text.
      e_msg-data = lt_data.
    ENDLOOP.
  ENDMETHOD.

ENDCLASS.
